package cn.xgj.sfzy.service.impl;

import cn.xgj.sfzy.entity.Article;
import cn.xgj.sfzy.entity.ArticleType;
import cn.xgj.sfzy.mapper.ArticleMapper;
import cn.xgj.sfzy.mapper.ArticleTypeMapper;
import cn.xgj.sfzy.service.ArticleService;
import cn.xgj.sfzy.service.ArticleTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName articleTypeServiceImpl
 * @Description TODO
 * @Author 李政阳
 * @Date 2024年10月23日 19:43
 * @Version 1.0
 */
@Service
public class ArticleTypeServiceImpl implements ArticleTypeService {

    @Autowired
    private ArticleTypeMapper mapper;
    @Autowired
    private ArticleMapper articleMapper;

    public int add(ArticleType articleType) {
        return mapper.add(articleType);
    }

    public int delete(Integer id) {
        List<Article> list = articleMapper.findByArticleTypeId(id);
        if (list.size()!=0){
            return -1;
        }else {
            return mapper.delete(id);
        }

    }

    public int update(ArticleType articleType) {
        return mapper.update(articleType);
    }

    @Override
    public List<ArticleType> findAll(ArticleType articleType) {
        return mapper.findAll(articleType);
    }


    @Override
    public PageInfo<ArticleType> findByPage(Integer pageNum, Integer pageSize, ArticleType articleType) {
        PageHelper.startPage(pageNum,pageSize);
        List<ArticleType> lis = mapper.findAll(articleType);
        PageInfo<ArticleType> info = new PageInfo<ArticleType>(lis);
        return info;
    }
}
